<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 指令练习</title>
    <script src="./js/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            color: #333;
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        header {
            text-align: center;
            margin-bottom: 40px;
            color: white;
            padding: 20px;
        }
        h1 {
            font-size: 2.8rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
        }
        .instructions {
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .instructions h2 {
            color: #2575fc;
            margin-bottom: 15px;
            border-bottom: 2px solid #eee;
            padding-bottom: 10px;
        }
        .instructions ul {
            padding-left: 20px;
            margin-bottom: 15px;
        }
        .instructions li {
            margin-bottom: 8px;
            line-height: 1.5;
        }
        .practice-area {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
        }
        @media (max-width: 768px) {
            .practice-area {
                grid-template-columns: 1fr;
            }
        }
        .card {
            background-color: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
        }
        .card-header {
            background-color: #2575fc;
            color: white;
            padding: 15px 20px;
            font-size: 1.3rem;
            font-weight: 600;
        }
        .card-body {
            padding: 20px;
        }
        .example {
            margin-bottom: 25px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
        }
        .example:last-child {
            border-bottom: none;
            margin-bottom: 0;
            padding-bottom: 0;
        }
        .example-title {
            font-size: 1.1rem;
            font-weight: 600;
            margin-bottom: 10px;
            color: #2575fc;
        }
        .code {
            background-color: #f5f7fa;
            border-left: 4px solid #2575fc;
            padding: 10px 15px;
            margin: 10px 0;
            font-family: 'Courier New', monospace;
            border-radius: 0 5px 5px 0;
            overflow-x: auto;
        }
        .demo {
            margin: 15px 0;
            padding: 15px;
            background-color: #f9f9f9;
            border-radius: 5px;
        }
        .btn {
            background-color: #2575fc;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            transition: background-color 0.3s;
            margin: 5px;
        }
        .btn:hover {
            background-color: #1a68e8;
        }
        .btn-danger {
            background-color: #ff4757;
        }
        .btn-danger:hover {
            background-color: #ff3742;
        }
        .btn-success {
            background-color: #2ed573;
        }
        .btn-success:hover {
            background-color: #25c768;
        }
        .highlight {
            background-color: #fffacd;
            padding: 2px 5px;
            border-radius: 3px;
        }
        .toggle-content {
            padding: 15px;
            background-color: #e3f2fd;
            border-radius: 5px;
            margin-top: 10px;
            transition: all 0.3s ease;
        }
        .image-container {
            width: 100%;
            height: 200px;
            overflow: hidden;
            border-radius: 5px;
            margin: 10px 0;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #f5f7fa;
        }
        .image-container img {
            max-width: 100%;
            max-height: 100%;
            transition: all 0.3s ease;
        }
        .counter {
            font-size: 2rem;
            font-weight: bold;
            color: #2575fc;
            text-align: center;
            margin: 15px 0;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
        }
        .form-control {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        .status {
            padding: 10px;
            border-radius: 5px;
            margin-top: 10px;
            text-align: center;
            font-weight: 500;
        }
        .status-active {
            background-color: #d4edda;
            color: #155724;
        }
        .status-inactive {
            background-color: #f8d7da;
            color: #721c24;
        }
        .progress-bar {
            height: 20px;
            background-color: #e9ecef;
            border-radius: 10px;
            overflow: hidden;
            margin: 15px 0;
        }
        .progress {
            height: 100%;
            background-color: #2575fc;
            transition: width 0.3s ease;
        }
        footer {
            text-align: center;
            margin-top: 40px;
            color: white;
            padding: 20px;
            opacity: 0.8;
        }
    </style>
</head>
<body>
    <div id="app" class="container">
        <header>
            <h1>Vue 指令练习</h1>
            <p class="subtitle">掌握 v-show, v-bind 和 v-on 的使用方法</p>
        </header>
        
        <section class="instructions">
            <h2>指令说明</h2>
            <ul>
                <li><span class="highlight">v-show</span>: 根据表达式的真假值，切换元素的 display CSS 属性</li>
                <li><span class="highlight">v-bind</span>: 动态绑定一个或多个属性，或一个组件 prop 到表达式</li>
                <li><span class="highlight">v-on</span>: 绑定事件监听器，用于监听 DOM 事件</li>
            </ul>
            <p>在下面的练习中，你将通过实际操作来理解这些指令的用法。每个示例都包含代码和实时演示。</p>
        </section>
        
        <div class="practice-area">
            <!-- v-show 练习 -->
            <div class="card">
                <div class="card-header">v-show 练习</div>
                <div class="card-body">
                    <div class="example">
                        <div class="example-title">1. 切换元素显示</div>
                        <div class="code">&lt;div v-show="isVisible"&gt;{{ message }}&lt;/div&gt;</div>
                        <div class="demo">
                            <button class="btn" @click="toggleVisibility">切换显示</button>
                            <div class="toggle-content" v-show="isVisible">
                                {{ message }}
                            </div>
                        </div>
                    </div>
                    
                    <div class="example">
                        <div class="example-title">2. 条件显示状态</div>
                        <div class="code">&lt;div v-show="status === 'active'" class="status status-active"&gt;活跃状态&lt;/div&gt;</div>
                        <div class="demo">
                            <button class="btn" @click="toggleStatus">切换状态</button>
                            <div v-show="status === 'active'" class="status status-active">
                                当前状态：活跃
                            </div>
                            <div v-show="status === 'inactive'" class="status status-inactive">
                                当前状态：非活跃
                            </div>
                        </div>
                    </div>
                    
                    <div class="example">
                        <div class="example-title">3. 表单验证显示</div>
                        <div class="code">&lt;div v-show="email.length > 0 && !isValidEmail"&gt;请输入有效的电子邮件地址&lt;/div&gt;</div>
                        <div class="demo">
                            <div class="form-group">
                                <label for="email">电子邮件:</label>
                                <input type="email" id="email" class="form-control" v-model="email" placeholder="输入电子邮件">
                            </div>
                            <div v-show="email.length > 0 && !isValidEmail" class="status status-inactive">
                                请输入有效的电子邮件地址
                            </div>
                            <div v-show="isValidEmail" class="status status-active">
                                电子邮件格式正确
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- v-bind 和 v-on 练习 -->
            <div class="card">
                <div class="card-header">v-bind 和 v-on 练习</div>
                <div class="card-body">
                    <div class="example">
                        <div class="example-title">1. 动态绑定样式</div>
                        <div class="code">&lt;div v-bind:style="{ backgroundColor: bgColor }"&gt;{{ bgColor }} 背景&lt;/div&gt;</div>
                        <div class="demo">
                            <button class="btn" @click="changeColor('lightblue')">浅蓝色</button>
                            <button class="btn btn-success" @click="changeColor('lightgreen')">浅绿色</button>
                            <button class="btn btn-danger" @click="changeColor('lightcoral')">浅红色</button>
                            <div class="toggle-content" v-bind:style="{ backgroundColor: bgColor, padding: '15px', borderRadius: '5px', marginTop: '10px' }">
                                {{ bgColor }} 背景
                            </div>
                        </div>
                    </div>
                    
                    <div class="example">
                        <div class="example-title">2. 动态绑定图片</div>
                        <div class="code">&lt;img v-bind:src="imageUrl" v-bind:alt="imageAlt"&gt;</div>
                        <div class="demo">
                            <button class="btn" @click="changeImage('vue')">Vue 图片</button>
                            <button class="btn" @click="changeImage('js')">JavaScript 图片</button>
                            <button class="btn" @click="changeImage('html')">HTML 图片</button>
                            <div class="image-container">
                                <img v-bind:src="imageUrl" v-bind:alt="imageAlt">
                            </div>
                            <p>当前图片: {{ imageAlt }}</p>
                        </div>
                    </div>
                    
                    <div class="example">
                        <div class="example-title">3. 计数器与进度条</div>
                        <div class="code">
                            &lt;button v-on:click="increment"&gt;增加&lt;/button&gt;<br>
                            &lt;button v-on:click="decrement"&gt;减少&lt;/button&gt;<br>
                            &lt;div class="progress-bar"&gt;<br>
                            &nbsp;&nbsp;&lt;div class="progress" v-bind:style="{ width: progress + '%' }"&gt;&lt;/div&gt;<br>
                            &lt;/div&gt;
                        </div>
                        <div class="demo">
                            <button class="btn" @click="increment">增加</button>
                            <button class="btn" @click="decrement">减少</button>
                            <button class="btn btn-danger" @click="resetCounter">重置</button>
                            <div class="counter">{{ counter }}</div>
                            <div class="progress-bar">
                                <div class="progress" v-bind:style="{ width: progress + '%' }"></div>
                            </div>
                            <p>进度: {{ progress }}%</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <footer>
            <p>Vue 指令练习作业 - 通过实践掌握 Vue 基础知识</p>
        </footer>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                // v-show 相关数据
                isVisible: true,
                message: '这是一个可以通过v-show切换显示的内容！',
                status: 'active',
                email: '',
                
                // v-bind 和 v-on 相关数据
                bgColor: 'lightblue',
                imageType: 'vue',
                imageAlt: 'Vue Logo',
                counter: 0
            },
            methods: {
                // v-show 相关方法
                toggleVisibility() {
                    
                },
                // v-bind 和 v-on 相关方法 
                toggleStatus() {
                    this.status = this.status === 'active' ? 'inactive' : 'active';
                },
                
                // v-bind 和 v-on 相关方法
                changeColor(color) {
                    this.bgColor = color;
                },
                changeImage(type) {
                    this.imageType = type;
                    const altTexts = {
                        vue: 'Vue Logo',
                        js: 'JavaScript Logo',
                        html: 'HTML5 Logo'
                    };
                    this.imageAlt = altTexts[type] || 'Vue Logo';
                },
                increment() {
                    this.counter++;
                },
                decrement() {
                    if (this.counter > 0) {
                        this.counter--;
                    }
                },
                resetCounter() {
                    this.counter = 0;
                }
            }
        });
    </script>
</body>
</html>